<?php
namespace app\admin\model;
use think\Model;

class Occupy extends model{
	function finduid($id){
		$res = model('occupy')->where('user_id',$id)->find();
		return $res;
	}
    function finduid2($id){
        $res = db('occupy')->where('user_id',$id)->select();
        return $res;
    }
	function win($user_id,$price,&$data){

        	model('user')->where(['id'=>$user_id])->setDec('employ' , $price);
    		//按占成扣成
            $occupy = model("occupy")->where(['user_id'=>$user_id])->find();
            //where('id=5')->setDec('score',5); 
            //
            $dl = $price*$occupy['daili']/100;
            $zd = $price*$occupy['zongdai']/100;
            $gd = $price*$occupy['gudong']/100;
            $dgd = $price*$occupy['dagudong']/100;
            $zj = $price*$occupy['zongjian']/100;
            $ht = $price*$occupy['houtai']/100;

            $user = model('user')->find($user_id);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$dl);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$zd);

    	    $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$gd);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$dgd);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$zj);

    	    $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$ht);



            $data['user1'] = $data['user1'] - $ht;
            $data['user2'] = $data['user2'] - $zj;
            $data['user3'] = $data['user3'] - $dgd;
            $data['user4'] = $data['user4'] - $gd;
            $data['user5'] = $data['user5'] - $zd;
            $data['user6'] = $data['user6'] - $dl;
            $data['user7'] += $price;

            $data['user7real'] = $price;
	}
        function ts($user_id,$price,&$data){

                //按占成扣成
                $occupy = model("occupy")->where(['user_id'=>$user_id])->find();

                $user = model('user')->find($user_id);
                model('user')->where(['id'=>$user_id])->setDec('employ',$price);


                $dl = $price*$occupy['daili']/100;
                $zd = $price*$occupy['zongdai']/100;
                $gd = $price*$occupy['gudong']/100;
                $dgd = $price*$occupy['dagudong']/100;
                $zj = $price*$occupy['zongjian']/100;
                $ht = $price*$occupy['houtai']/100;

                model('user')->where(['id'=>$user['topuser']])->setInc('employ',$dl);

                $user = model('user')->find($user['topuser']);
                model('user')->where(['id'=>$user['topuser']])->setInc('employ',$zd);

                $user = model('user')->find($user['topuser']);
                model('user')->where(['id'=>$user['topuser']])->setInc('employ',$gd);

                $user = model('user')->find($user['topuser']);
                model('user')->where(['id'=>$user['topuser']])->setInc('employ',$dgd);

                $user = model('user')->find($user['topuser']);
                model('user')->where(['id'=>$user['topuser']])->setInc('employ',$zj);

                $user = model('user')->find($user['topuser']);
                model('user')->where(['id'=>$user['topuser']])->setInc('employ',$ht);


                $data['u7tuishui'] = $price;
                $data['u6tuishui'] = $dl;
                $data['u5tuishui'] = $zd;
                $data['u4tuishui'] = $gd;
                $data['u3tuishui'] = $dgd;
                $data['u2tuishui'] = $zj;
                $data['u1tuishui'] = $ht;


                $data['user1'] = $data['allorder']*$occupy['houtai']/100 - $data['u1tuishui'];
                $data['user2'] = $data['allorder']*$occupy['zongjian']/100 - $data['u2tuishui'];
                $data['user3'] = $data['allorder']*$occupy['dagudong']/100 - $data['u3tuishui'];
                $data['user4'] = $data['allorder']*$occupy['gudong']/100 - $data['u4tuishui'];
                $data['user5'] = $data['allorder']*$occupy['zongdai']/100 - $data['u5tuishui'];
                $data['user6'] = $data['allorder']*$occupy['daili']/100 - $data['u6tuishui'];
                $data['user7'] = $data['u7tuishui'] - $data['allorder'];

                $data['user7real'] = 0;
        }
        function dogfall($user_id,$price,&$data){

            model('user')->where(['id'=>$user_id])->setDec('employ' , $price);
            //按占成扣成
            $occupy = db("occupy")->where(['user_id'=>$user_id])->find();
            //where('id=5')->setDec('score',5); 

            $dl = $price*$occupy['daili']/100;
            $zd = $price*$occupy['zongdai']/100;
            $gd = $price*$occupy['gudong']/100;
            $dgd = $price*$occupy['dagudong']/100;
            $zj = $price*$occupy['zongjian']/100;
            $ht = $price*$occupy['houtai']/100;

            $user = model('user')->find($user_id);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$dl);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$zd);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$gd);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$dgd);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$zj);

            $user = model('user')->find($user['topuser']);
            model('user')->where(['id'=>$user['topuser']])->setInc('employ',$ht);


            $data['user1'] -= $ht;
            $data['user2'] -= $zj;
            $data['user3'] -= $dgd;
            $data['user4'] -= $gd;
            $data['user5'] -= $zd;
            $data['user6'] -= $dl;
            $data['user7'] += $price;

            $data['user7real'] = -$price;

        }
        function tsinser($p,$bet,$c,$bets,$uid){
                // 退水接口
                if($bet==1 && $c=2 && $bet<50){
                    $n = 1;
                }
                if($bet==1 && $c=1 && $bet<50){
                    $n = 2;
                }
                if($bet==1 && $bets==50){
                    // 特尾大
                    $n =27 ;
                }
                if($bet==1 && $bets==51){
                    // 特尾小
                   $n =27;  
                }
                if($bet==1 &&$bet==52){
                    // 特单
                   $n = 3; 
                }
                if($bet==1 &&$bet==53){
                    // 特双
                   $n = 3; 
                }
                if($bet==1 &&$bet==54){
                    // 特大
                   $n = 4 ;
                }
                if($bet==1 &&$bet==55){
                    // 特小
                   $n = 4 ;
                }
                if($bet==1 &&$bet==56){
                    // 合双
                  $n =  5;
                }
                if($bet==1 &&$bet==57){
                    // 合单
                   $n =  5;
                }
                if($bet==1 &&$bet==58){
                    // 总单
                  $n =  7;
                }
                if($bet==1 &&$bet==59){
                    // 总双
                  $n =  7;
                }
                if($bet==1 &&$bet==60){
                    // 总大
                  $n =  8;
                }
                if($bet==1 &&$bet==61){
                    // 总小
                   $n =  8;
                   
                }
                if($bet==1 &&$bet==62){
                    // 红
                 $n =  9;
                }
                if($bet==1 &&$bet==63){
                    // 绿
                  $n =  9;
                }
                if($bet==1 &&$bet==64){
                    // 蓝
                  $n =  9;
                }
                if($bet==1 &&$bet==65){
                    // 合大
                  $n =  26;
                }  
                if($bet==1 &&$bet==65){
                    // 合小
                   $n = 26;
                } 
                if($bet==1 &&$bet==66){
                    // 大单
                   $n =  28;
                } 
                if($bet==1 &&$bet==67){
                    // 大双
                   $n =  28;
                } 
                if($bet==1 &&$bet==68){
                    // 小单
                   $n =  28;
                } 
                if($bet==1 &&$bet==69){
                    // 小双
                    $n = 28;
                }
                if($bet==2){
                    // 正码
                    $n = 6;
                }
                if($bet==6&&$bets<13){
                    // 特码生肖
                    $n=10;
                }
                if($bet==4){
                    if($bets==1||$bets==10||$bets==19||$bets==28||$bets==37||$bets==46||$bets==2||$bets==11||$bets==20||$bets==29|$bets==38||$bets==47){
                        $n = 11;
                    }
                    if($bets==3||$bets==12||$bets==21||$bets==30||$bets==39||$bets==48||$bets==4||$bets==13||$bets==22||$bets==31|$bets==40||$bets==49){
                        $n = 12;
                    }
                    if($bets==5||$bets==14||$bets==23||$bets==32||$bets==41||$bets==50||$bets==6||$bets==15||$bets==24||$bets==33|$bets==42||$bets==51||$bets==7|$bets==16||$bets==25||$bets==34|$bets==43||$bets==52){
                        $n = 13;
                    }
                    if($bets==8||$bets==17||$bets==26||$bets==35||$bets==44||$bets==57||$bets==9||$bets==18||$bets==27||$bets==36|$bets==45||$bets==54){
                        $n = 14;
                    }
                }
                if($bet==8){
                    $n=15;
                }
                 if($bet==12){
                    $n=16;
                }
                if($bet==13&&$c==1){
                    $n=17;
                }
                if($bet==6&&$bets>17&&$bets<=27){
                    $n=18;
                }
                if($bet==7){
                    if($c==1){
                        $n = 19;
                    }
                     if($c==2){
                        $n = 20;
                    }
                    if($c==3){
                        $n = 21;
                    }
                    if($c==4){
                        $n = 22;
                    }
                        $n = 23;

                }
                if($bet==13&&$bets>27){
                    $n = 24;
                }
                if($bet==3){
                    $n= 25;
                }
                if($bet==6&&$bets>12&&$bets<=17){
                    $n=29;
                }
                if($bet==6&&$bets<=27&&$bets>17){
                    $n=30;
                }
                if($bet==9&&$bets>12&&$bets<=16){
                    $n=31;
                }
                if($bet==9&&$bets>16&&$bets<=18){
                    $n=32;
                }
                if($bet==9&&$bets<13){
                    $n=33;
                }
                if($bet==10){
                    $n=34;
                }
                if($bet==5){
                    $n=35;
                }
                if($bet==14){
                    if($c==1){
                        $n=36;
                    }
                    if($c==2){
                        $n=37;
                    }
                    if($c==3){
                        $n=38;
                    }
                    if($c==4){
                        $n=39;
                    }
                    if($c==5){
                        $n=40;
                    }
                    if($c==6){
                        $n=41;
                    }
                    if($c==7){
                        $n=42;
                    }
                        $n=43;
                    
                }
                if($bet==15){
                    if($c==1){
                        $n=44;
                    }
                    if($c==2){
                       $n=45;  
                    }
                    if($c==3){
                        $n=46; 
                    }
                    if($c==4){
                        $n=47; 
                    }
                }
                if($bet==13&&$c==2){
                    $n=48;
                }
                if($bet==11){
                    $n=49;
                }
                if($bet==9&&$bets>19){
                    $n=50;
                }
                $res = model('returnwater')->findwater($p,$n,$uid);
                return $res;
            }
        }